/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.edu.thu.laud.objectstore.index;

/**
 * IndexContainer represents the containing entity's key and collection
 * name. The assumption is that an entity can have multiple collections,
 * each with their own name.
 * @author zhuoan
 */
public  class IndexContainer {

	private String ownerKey;
	private String containerName;
	private boolean unique = false;

	public IndexContainer(String ownerKey, String collectionName) {
		this.ownerKey = ownerKey;
		this.containerName = collectionName;
	}

	public boolean isUnique() {
		return unique;
	}

	public void setUnique(boolean unique) {
		this.unique = unique;
	}

	public String getOwnerKey() {
		return ownerKey;
	}

	public void setOwnerKey(String ownerKey) {
		this.ownerKey = ownerKey;
	}

	public String getContainerName() {
		return containerName;
	}

	public void setContainerName(String collectionName) {
		this.containerName = collectionName;
	}

	public String getKey() {
		return ownerKey + ":" + containerName;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((containerName == null) ? 0 : containerName.hashCode());
		result = prime * result
				+ ((ownerKey == null) ? 0 : ownerKey.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}

		IndexContainer other = (IndexContainer) obj;
		if (containerName == null) {
			if (other.containerName != null) {
				return false;
			}
		} else if (!containerName.equals(other.containerName)) {
			return false;
		}
		if (ownerKey == null) {
			if (other.ownerKey != null) {
				return false;
			}
		} else if (!ownerKey.equals(other.ownerKey)) {
			return false;
		}
		return true;
	}
}
